#ifndef __F1TDC__
#define __F1TDC__

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <cstdio>

class F1TDC{
 public:
  F1TDC();
  F1TDC(const char *char_wrd);
  ~F1TDC();

  void Decode(const char *char_wrd);
  std::string GetDecodedData() {return return_decoded_data;};
 
  

 private:

  static const unsigned int F1_SLOT_ID_MASK;
  static const unsigned int F1_RESOLUTION_LOCKED_MASK;
  static const unsigned int F1_OUTPUT_FIFO_OVERFLOW_MASK;
  static const unsigned int F1_HIT_FIFO_OVERFLOW_MASK;
  static const unsigned int F1_DATA_TYPE_MASK;
  static const unsigned int F1_DATA_MASK;
  static const unsigned int F1_CHANNEL_NUMBER_MASK;

  static const unsigned int F1_HT_TRIG_FIFO_MASK;
  static const unsigned int F1_HT_EVENT_NUMBER_MASK;
  static const unsigned int F1_HT_TRIG_TIME_MASK;
  static const unsigned int F1_HT_XOR_SETUP_REG_MASK;
  static const unsigned int F1_HT_CHANNEL_NUMBER_MASK;
 
  unsigned int  slot_id;
  unsigned int  resolution_locked;      // true(1) if word is 1
  unsigned int  output_fifo_overflow;   // true(1) if word is 1
  unsigned int  hit_fifo_overflow;      // 1 : hit FIFO overflow

  unsigned int  data_type;              // 0 : header/trailer, 1 : data 
  unsigned int  data;
  unsigned int  channel_number;

  unsigned int  header_trigger_fifo_overflow;
  unsigned int  header_event_number;
  unsigned int  header_trigger_time;
  unsigned int  header_xor_setup_reg;
  unsigned int  header_channel_number;
 
  std::string         return_decoded_data;
  std::ostringstream  decoded_stream;

  bool valid_slot_flag;  
  // Slot 1 - 21 indicates valid data
  // Slot 0  is the tag for a "filler" word. This is a non-valid data word that is
  //         inserted to make the block of data output from the module consist of
  //         an "even" number of words.
  // Slot 30 : the module will return 30 when the data is not valid
 
  bool data_input_flag;

  // unsigned int GetSlotID()               {return slot_id;};
  // unsigned int GetResolutionLocked()     {return resolution_locked;};
  // unsigned int GetOutputFifoOverflow()   {return output_fifo_overflow;};
  // unsigned int GetHitFifoOverflow()      {return hit_fifo_overflow;};

  // unsigned int GetDataType()             {return data_type;};
  // unsigned int GetData()                 {return data;};
  // unsigned int GetChannelNumber()        {return channel_number;};

  // unsigned int GetHeaderTrigFFOverflow() {return header_trigger_fifo_overflow;};
  // unsigned int GetHeaderEventNumber()    {return header_event_number;};
  // unsigned int GetHeaderTriggerTime()    {return header_trigger_time;};
  // unsigned int GetHeaderXorSetupReg()    {return header_xor_setup_reg;};
  
  unsigned int BitMaskShift(long int wrd, unsigned int mask, unsigned short shift)
  {
    return ( (wrd&mask)>>shift );
  }

  // F1TDC class Debug Purpose
  void   PrintHeader();
  void   PrintData();
  
};



#endif
